// Tool Definitions

import { ToolDefinition, ToolCategory } from './interfaces';

/**
 * 文件操作工具定义
 */
export const FILE_OPERATION_TOOLS: Record<string, ToolDefinition> = {
    'read-file': {
        name: 'read-file',
        description: '读取文件内容',
        category: ToolCategory.FILE_OPERATIONS,
        parameters: [
            {
                name: 'path',
                type: 'string',
                required: true,
                description: '文件路径'
            },
            {
                name: 'encoding',
                type: 'string',
                required: false,
                description: '文件编码',
                default: 'utf8'
            }
        ],
        timeout: 10000,
        isAsync: true
    },

    'save-file': {
        name: 'save-file',
        description: '保存文件',
        category: ToolCategory.FILE_OPERATIONS,
        parameters: [
            {
                name: 'path',
                type: 'string',
                required: true,
                description: '文件路径'
            },
            {
                name: 'content',
                type: 'string',
                required: true,
                description: '文件内容'
            },
            {
                name: 'encoding',
                type: 'string',
                required: false,
                description: '文件编码',
                default: 'utf8'
            },
            {
                name: 'add_last_line_newline',
                type: 'boolean',
                required: false,
                description: '是否在文件末尾添加换行符',
                default: true
            }
        ],
        timeout: 10000,
        requiresPermissions: ['file:write'],
        isAsync: true
    },

    'str-replace-editor': {
        name: 'str-replace-editor',
        description: '字符串替换编辑器',
        category: ToolCategory.FILE_OPERATIONS,
        parameters: [
            {
                name: 'path',
                type: 'string',
                required: true,
                description: '文件路径'
            },
            {
                name: 'old_str',
                type: 'string',
                required: true,
                description: '要替换的旧字符串'
            },
            {
                name: 'new_str',
                type: 'string',
                required: true,
                description: '新字符串'
            },
            {
                name: 'old_str_start_line_number',
                type: 'number',
                required: true,
                description: '旧字符串开始行号'
            },
            {
                name: 'old_str_end_line_number',
                type: 'number',
                required: true,
                description: '旧字符串结束行号'
            }
        ],
        timeout: 10000,
        requiresPermissions: ['file:write'],
        isAsync: true
    }
};

/**
 * 记忆管理工具定义
 */
export const MEMORY_MANAGEMENT_TOOLS: Record<string, ToolDefinition> = {
    'remember': {
        name: 'remember',
        description: '创建记忆项',
        category: ToolCategory.MEMORY_MANAGEMENT,
        parameters: [
            {
                name: 'memory',
                type: 'string',
                required: true,
                description: '要记住的内容'
            }
        ],
        timeout: 5000,
        isAsync: true
    },

    'memory-retrieval': {
        name: 'memory-retrieval',
        description: '检索记忆',
        category: ToolCategory.MEMORY_MANAGEMENT,
        parameters: [
            {
                name: 'query',
                type: 'string',
                required: true,
                description: '检索查询'
            },
            {
                name: 'limit',
                type: 'number',
                required: false,
                description: '返回结果数量限制',
                default: 10
            }
        ],
        timeout: 5000,
        isAsync: true
    }
};

/**
 * 进程管理工具定义
 */
export const PROCESS_MANAGEMENT_TOOLS: Record<string, ToolDefinition> = {
    'launch-process': {
        name: 'launch-process',
        description: '启动进程',
        category: ToolCategory.PROCESS_MANAGEMENT,
        parameters: [
            {
                name: 'command',
                type: 'string',
                required: true,
                description: '要执行的命令'
            },
            {
                name: 'wait',
                type: 'boolean',
                required: true,
                description: '是否等待进程完成'
            },
            {
                name: 'max_wait_seconds',
                type: 'number',
                required: true,
                description: '最大等待时间（秒）'
            },
            {
                name: 'cwd',
                type: 'string',
                required: true,
                description: '工作目录'
            }
        ],
        timeout: 300000, // 5分钟
        requiresPermissions: ['process:execute'],
        isAsync: true
    },

    'kill-process': {
        name: 'kill-process',
        description: '终止进程',
        category: ToolCategory.PROCESS_MANAGEMENT,
        parameters: [
            {
                name: 'terminal_id',
                type: 'number',
                required: true,
                description: '终端ID'
            }
        ],
        timeout: 5000,
        requiresPermissions: ['process:kill'],
        isAsync: true
    },

    'read-process': {
        name: 'read-process',
        description: '读取进程输出',
        category: ToolCategory.PROCESS_MANAGEMENT,
        parameters: [
            {
                name: 'terminal_id',
                type: 'number',
                required: true,
                description: '终端ID'
            },
            {
                name: 'wait',
                type: 'boolean',
                required: true,
                description: '是否等待进程完成'
            },
            {
                name: 'max_wait_seconds',
                type: 'number',
                required: true,
                description: '最大等待时间（秒）'
            }
        ],
        timeout: 300000, // 5分钟
        requiresPermissions: ['process:read'],
        isAsync: true
    },

    'write-process': {
        name: 'write-process',
        description: '向进程写入输入',
        category: ToolCategory.PROCESS_MANAGEMENT,
        parameters: [
            {
                name: 'terminal_id',
                type: 'number',
                required: true,
                description: '终端ID'
            },
            {
                name: 'input_text',
                type: 'string',
                required: true,
                description: '要写入的文本'
            }
        ],
        timeout: 5000,
        requiresPermissions: ['process:write'],
        isAsync: true
    },

    'list-processes': {
        name: 'list-processes',
        description: '列出所有进程',
        category: ToolCategory.PROCESS_MANAGEMENT,
        parameters: [],
        timeout: 5000,
        requiresPermissions: ['process:list'],
        isAsync: true
    }
};
